﻿<%@ WebHandler Language="C#" Class="RefundManager" %>

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json;

public class RefundManager : IHttpHandler,System.Web.SessionState.IReadOnlySessionState {
    
    public void ProcessRequest (HttpContext context) {
        OTS.Common.Page<OTS.Model.saleOrder> page = new OTS.Common.Page<OTS.Model.saleOrder>();
        if (!OTS.BaseLogin.validataModule(context,(int)OTS.enumSysRight.RefundManager))
        {
            page.success = false;
            page.msg = "非法操作！";
        }
        else
        {
            string limit = context.Request["limit"];
            string start = context.Request["start"];
            int limitInt = 20;
            int startInt = 0;
            if (null!=limit&&OTS.Common.Help.IsNumber(limit))
            {
                limitInt = int.Parse(limit);
            }
            if (null!=start&&OTS.Common.Help.IsNumber(start))
            {
                startInt = int.Parse(start);
            }

            string orderNO = context.Request["orderNO"];
            string loginname = context.Request["loginname"];
            string status = context.Request["refund"];
            if (null==orderNO)
            {
                orderNO = "";
            }
            if (null==loginname)
            {
                loginname = "";
            }
            if (null==status)
            {
                status = "";
            }
            else if (status=="-1")
            {
                status = "";
            }

            OTS.BLL.SaleOrderBLL bll = new OTS.BLL.SaleOrderBLL();
            string strWhere = "";
            if (orderNO==""&&loginname==""&&status=="")
            {
                strWhere = " refund<>0";
                page = bll.GetListByPage(startInt, limitInt, strWhere);
            }
            else
            {
                strWhere = " 1=1";
                if (orderNO!="")
                {
                    strWhere += " and orderNO='" + OTS.DAL.DBUtility.Database.GetSQLString(orderNO) + "'";
                }
                if (loginname!="")
                {
                    OTS.BLL.CustomBLL bllCus = new OTS.BLL.CustomBLL();
                    int cusID = bllCus.GetCusIdByLoginName(loginname);
                    if (cusID>0)
                    {
                        strWhere += " and salesOrder.cusID=" + cusID.ToString();
                    }
                    else
                    {
                        strWhere += " and 1=2";
                    }
                }
                if (status=="1")
                {
                    strWhere += " and refund=1 or refund=2";
                }
                else if (status=="0")
                {
                    strWhere += " and refund=3";
                }
                page = bll.GetListByPage(startInt, limitInt, strWhere);
            }
        }

        context.Response.ContentType = "application/x-json";
        context.Response.Charset = "utf-8";
        context.Response.Write(JavaScriptConvert.SerializeObject(page));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}